package com.bilibili.juc.interrupt;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

public class InterruptTestDemo02 {

    //static volatile boolean isStop = false;
    //static  boolean isStop = false ;

    static AtomicBoolean isStop = new AtomicBoolean(false) ;


    public static void main(String[] args) {
        new Thread(
                ()->{
                    while(true){
                        if(isStop.get()){
                            System.out.println(Thread.currentThread().getName()+"\t isStop 修改为ture,程序停止");
                            break;
                        }
                        System.out.println("---- hello AtomicBoolean t1");
                    }

                },"t1"
        ).start();

        try{
            TimeUnit.MILLISECONDS.sleep(10);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        new Thread(
                ()->{
                    System.out.println(Thread.currentThread().getName()+"-------");
                    isStop.set(true);
                    System.out.println(Thread.currentThread().getName()+"after-------");
                },"t2"
        ).start();

        System.out.println(Thread.currentThread().getName()+"-------");
    }
}
